﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Lohnefink3D
{
    class GameObject
    {

        Matrix world;
        Model modelo;

        private BasicEffect effect;

        public Matrix rotationMatrix = Matrix.Identity;
        public Matrix scaleMatrix = Matrix.Identity;
        public Matrix translationMatrix = Matrix.Identity;

        public GameObject(Model modelo)
        {
            this.world = this.rotationMatrix * this.scaleMatrix * this.translationMatrix;
            this.modelo = modelo;
        }

        public void Update(KeyboardState keyboard)
        {
            if (keyboard.IsKeyDown(Keys.R))
            {
                rotationMatrix *= Matrix.CreateRotationX(0.01f) * Matrix.CreateRotationY(0.01f);
            }

            if (keyboard.IsKeyDown(Keys.E) && keyboard.IsKeyDown(Keys.PageUp))
            {
                scaleMatrix *= Matrix.CreateScale(1.01f);
            }

            if (keyboard.IsKeyDown(Keys.E) && keyboard.IsKeyDown(Keys.PageUp))
            {
                scaleMatrix *= Matrix.CreateScale(1.01f);
            }

            else if (keyboard.IsKeyDown(Keys.E) && keyboard.IsKeyDown(Keys.PageDown))
            {
                scaleMatrix *= Matrix.CreateScale(0.99f);
            }

            if (keyboard.IsKeyDown(Keys.T))
            {
                if (keyboard.IsKeyDown(Keys.Left))
                {
                    translationMatrix *= Matrix.CreateTranslation(-0.05f, 0, 0);
                }

                if (keyboard.IsKeyDown(Keys.Right))
                {
                    translationMatrix *= Matrix.CreateTranslation(0.05f, 0, 0);
                }

                if (keyboard.IsKeyDown(Keys.Up))
                {
                    translationMatrix *= Matrix.CreateTranslation(0, 0.05f, 0);
                }

                if (keyboard.IsKeyDown(Keys.Down))
                {
                    translationMatrix *= Matrix.CreateTranslation(0, -0.05f, 0);
                }
            }
        }

        public void Draw(Camera camera)
        {
            this.world = this.rotationMatrix * this.scaleMatrix * this.translationMatrix;
            this.modelo.Draw(world, camera.view, camera.projection);
        }
    }
}
